<style scoped lang="stylus" type="text/stylus">
  .change-pw-page {
    height : 100%
    .edit-header {
      position : fixed
      top : 0
      height : 60px
      line-height : 60px;
      padding-left : 40px;
      font-size : 18px;
      background-color : #4c4c4c
      .route-title {
        color : #fff
        cursor : pointer
      }
      .page-name {
        color : #7f7f7f
      }
    }
    .con {
      width : 480px;
      margin : 0px auto 0;
      position : relative;
      top : 160px;
    }
    .alert {
      height : 30px
      margin-bottom : 20px
      font-size : 18px;
      color : #4c4c4c;
      text-align : center
    }
    input {
      display : block
      width : 100%
      height : 60px
      margin-bottom : 40px
      line-height : 60px
      font-size : 50px;
      color : #4B4F5F;
      text-align : center
      border : 0px solid #4B4F5F;
      background-color : #e5e5e5;
      &:focus {
        border-color : #fff
        color : #fff
      }
    }
    .sub {
      display : block
      width : 160px
      height : 40px
      margin : 65px auto 0
      font-size : 16px
      background-color : #4A96FF;
      border-radius 0
    }
    input[type="password"]::-webkit-input-placeholder {
      font-size : 18px;
      position : relative;
      top : -10px;
    }
  }


</style>

<template>
  <div class="change-pw-page">
    <div class="edit-header">
      <span @click="GoBack()" class="route-title">设置</span>
      <span class="page-name">&nbsp;/&nbsp;修改密码</span>
    </div>
    <div class="con">
      <div class="alert">{{alert}}</div>
      <input type="password" placeholder="输入当前密码" v-model="oldPasswd">
      <input type="password" placeholder="输入新密码" v-model="passwd">
      <input type="password" placeholder="确认新密码" v-model="passwdCheck">
      <Button class="sub" type="primary" @click="handleSubmit()">修改密码</Button>
    </div>
  </div>
</template>

<script type="text/ecmascript-6">
  import sha1 from 'js-sha1'
  import md5 from 'js-md5'

  export default {
    name      : 'ChangePw',
    data() {
      return {
        alert      : '',
        passwd     : '',
        passwdCheck: '',
        oldPasswd  : ''
      }
    },
    components: {},
    computed  : {},
    methods   : {
      handleSubmit() {
      const regTwo = /(?=.*[A-Z])(?=.*[a-z])(?!^\d+$)(?!^[a-zA-z]+$)[0-9a-zA-z]{8,23}/;
      if (this.oldPasswd == '') {
        this.$Notice.error({
          title:'错误',
          desc: '当前密码不能为空'
        })
        return;
      }
      if (this.passwd == "") {
        this.$Notice.error({
          title:'错误',
          desc: '请输入新密码'
        })
        return;
      }
      if (this.passwd.length < 8) {
        this.$Notice.error({
          title:'错误',
          desc: '密码至少大于等于8位'
        })
        return;
      }
      if (this.passwd.length > 24) {
        this.$Notice.error({
          title:'错误',
          desc: '密码不能大于24位'
        })
        return;
      }
      if (!regTwo.test(this.passwd)) {
        this.$Notice.error({
          title:'错误',
          desc: '密码只能由数字和字母和大写字母组成'
        })
        return;
      }
      if (this.passwdCheck == "") {
        this.$Notice.error({
          title:'错误',
          desc: '请再次输入新密码'
        })
        return;
      }
      if (this.passwdCheck !== this.passwd) {
        this.$Notice.error({
          title:'错误',
          desc: '两次输入密码不一致'
        })
        return;
      }

        this.alert = ''
        this.ajaxData({
          type: 'post',
          url : '/user/changePassword',
          data: {
            // password   : sha1(this.oldPasswd.toString()).toLowerCase(),
            // newPassword: sha1(this.passwd).toLowerCase()
            pwd   : sha1(this.oldPasswd.toString()).toLowerCase(),
            newpwd: sha1(this.passwd).toLowerCase()
          }
        }, (res, all) => {
          if (all.code == 0) {
            this.$Message.success('修改成功!');
//            sessionStorage.clear();
//            this.$router.push({path: '/login'})
          }
        })
      }
    },
    created() {}
  }
</script>
